<template>
    <div class="data-info" v-loading="loading">
        <div class="condition">
            <el-button type="primary" @click="save('help')" class="r5">添加帮助信息</el-button>
        </div>
        <el-table :data="data">
            <el-table-column label="ID" width="100" prop="id"/>
            <el-table-column label="标题" prop="title"/>
            <el-table-column label="操作">
                <template slot-scope="{row}">
                    <a class="success r5" @click="save(row)">编辑</a>
                    <a class="red" @click="del(row.id)">删除</a>
                </template>
            </el-table-column>
        </el-table>
        <page :total="total" :current.sync="params.page" :size.sync="params.size" @change="search"/>
    </div>
</template>

<script>
    import {docLists, docInfo} from "@/api";
    import save from "./com/save";
    import Page from "@/components/page/index";

    export default {
        components: {Page},
        data() {
            return {
                params: {
                    type: 1,
                    page: 1,
                    size: 10
                },
                loading: false,
                data: [],
                total: 0,
            }
        }
        , created() {
            this.search();
        }
        , methods: {
            search() {
                this.loading = true;
                docLists(this.params, (res) => {
                    this.loading = false;
                    this.data = res.lists;
                    this.total = parseInt(res.total);
                })
            }
            // 搜索
            , searchBtn() {
                this.params.page = 1;
                this.search();
            }
            , save(obj) {
                let title = '';
                if (obj == 'help') {
                    title = '添加帮助信息';
                } else {
                    title = '编辑帮助信息';
                }
                this.$drawer({
                    title: title,
                    component: save,
                    width: '50%',
                    data: obj,
                    close: this.search,
                })
            }
            , del(id) {
                this.$confirm('确定删除该帮助信息？', () => {
                    docInfo('delete', {id: id}, () => {
                        this.search();
                        this.$Modal.remove();
                    })
                })
            }
        }
    }
</script>
